//
//  ByChaseNumberListCell.m
//  caipiao_ios
//
//  Created by mc on 2018/8/13.
//  Copyright © 2018年 ZhangZhanbin. All rights reserved.
//

#import "ByChaseNumberListCell.h"

@implementation ByChaseNumberListCell

+ (instancetype)cellWithTableView:(UITableView*)tableView{
    
    static NSString *cellIdentifier = @"ByChaseNumberListCell";
    ByChaseNumberListCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (cell == nil) {
        cell = [[self alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
    }
    return cell;
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSeparatorStyleNone;
        self.contentView.backgroundColor = BY_BACKGROUND_COLOR;
    }
    return self;
}


- (void)initViews{
    [self.contentView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
    UIView *backgroundView = [[UIView alloc] init];
    [self.contentView addSubview:backgroundView];
    [backgroundView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(5);
        make.right.equalTo(self.contentView).offset(-5);
        make.top.equalTo(self.contentView).offset(7);
        make.bottom.equalTo(self.contentView).offset(0);
    }];
    backgroundView.layer.cornerRadius = 10;
    backgroundView.backgroundColor = [UIColor whiteColor];
    
    UIImageView *iconView = [[UIImageView alloc] init];
    [backgroundView addSubview:iconView];
    [iconView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(backgroundView).offset(13);
        make.top.equalTo(backgroundView).offset(9);
        make.size.mas_equalTo(CGSizeMake(45, 45));
    }];
    [iconView sd_setImageWithURL:[NSURL URLWithString:_netModel.img] placeholderImage:DEFAULT_IMAGE];
    
    
    UILabel *moneyLabel = [[UILabel alloc] init];
    [backgroundView addSubview:moneyLabel];
    [moneyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(backgroundView).offset(-48);
        make.top.equalTo(backgroundView).offset(20);
        make.height.mas_equalTo(@15);
        make.width.mas_equalTo(@100);
    }];
    moneyLabel.text = [NSString stringWithFormat:@"%@元",_netModel.amount];
    moneyLabel.font = FONT(15);
    moneyLabel.textColor = BY_THEME_COLOR;
    moneyLabel.textAlignment = NSTextAlignmentRight;
    
    UILabel *titleLabel = [[UILabel alloc] init];
    [backgroundView addSubview:titleLabel];
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(iconView.mas_left).offset(0);
        make.bottom.equalTo(backgroundView).offset(-11);
        make.height.mas_equalTo(@13);
        make.right.equalTo(iconView.mas_right).offset(0);
    }];
    titleLabel.text = _netModel.name;
    titleLabel.font = FONT(12);
    titleLabel.textColor = [UIColor blackColor];
    titleLabel.textAlignment = NSTextAlignmentCenter;
    
    UIImageView *arrowView = [[UIImageView alloc] init];
    [backgroundView addSubview:arrowView];
    [arrowView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(backgroundView).offset(-10);
        make.centerY.equalTo(iconView.mas_centerY).offset(0);
        make.size.mas_equalTo(CGSizeMake(15, 15));
    }];
    arrowView.image = [UIImage imageNamed:@"youjiantou1111"];
    
    
    UILabel *periodLabel = [[UILabel alloc] init];
    [backgroundView addSubview:periodLabel];
    [periodLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(backgroundView).offset(85);
        make.top.equalTo(backgroundView).offset(19);
        make.size.mas_offset(CGSizeMake(100, 16));
    }];
    periodLabel.text = [NSString stringWithFormat:@"剩%ld期/共%@期",_netModel.push_number.integerValue - _netModel.use_number.integerValue,_netModel.push_number];
    periodLabel.font = FONT(14);
    periodLabel.textColor = [UIColor blackColor];
    periodLabel.textAlignment = NSTextAlignmentLeft;
    
    
    UILabel *timeLabel = [[UILabel alloc] init];
    [backgroundView addSubview:timeLabel];
    [timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(periodLabel.mas_left).offset(0);
        make.bottom.equalTo(backgroundView).offset(-19);
        make.height.mas_equalTo(@13);
        make.right.equalTo(moneyLabel.mas_left).offset(0);
    }];
    timeLabel.text = _netModel.add_time;
    timeLabel.font = FONT(12);
    timeLabel.textColor = [UIColor lightGrayColor];
    timeLabel.textAlignment = NSTextAlignmentLeft;
    
    UILabel *typeLabel = [[UILabel alloc] init];
    [backgroundView addSubview:typeLabel];
    [typeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(moneyLabel.mas_left).offset(0);
        make.right.equalTo(moneyLabel.mas_right).offset(0);
        make.top.equalTo(timeLabel.mas_top).offset(0);
        make.height.mas_offset(@13);
    }];
    typeLabel.text = _netModel.is_rand.integerValue == 1 ? @"随机追号":@"固定追号";
    typeLabel.font = FONT(12);
    typeLabel.textColor = BY_TEXT_COLOR;
    typeLabel.textAlignment = NSTextAlignmentRight;
}

- (void)setNetModel:(ByNetModel *)netModel{
    
    _netModel = netModel;
    [self initViews];
}


@end
